﻿Imports EIBWatcherNet.Core.EIB.Interfaces
Imports EIBWatcherNet.Core.EIB.Bus.Addressing
Imports EIBWatcherNet.Core.EIBData

Namespace EIB.Managers
    Public NotInheritable Class EIBGroupAddressValueManager
        Implements IEIBManager(Of EIBGroupAddress, EIBDataContainer)

        Private _addresses As New Dictionary(Of UInt16, EIBDataContainer)


        Public Function Contains(address As EIBGroupAddress) As Boolean Implements IEIBManager(Of EIBGroupAddress, EIBDataContainer).Contains
            Return _addresses.ContainsKey(address.ToUint16)
        End Function

        Public Function GetValue(address As EIBGroupAddress) As EIBDataContainer Implements IEIBManager(Of EIBGroupAddress, EIBDataContainer).GetValue
            If _addresses.ContainsKey(address.ToUint16) Then
                Return _addresses(address.ToUint16)
            Else
                'not found
                Return Nothing
            End If
        End Function

        Public Sub SetValue(address As EIBGroupAddress, value As EIBDataContainer) Implements IEIBManager(Of EIBGroupAddress, EIBDataContainer).SetValue
            If _addresses.ContainsKey(address.ToUint16) Then
                _addresses(address.ToUint16) = value
            Else
                _addresses.Add(address.ToUint16, value)
            End If
        End Sub

        Public Sub Clear() Implements IEIBManager(Of EIBGroupAddress, EIBDataContainer).Clear
            _addresses.Clear()
        End Sub

        Public Sub Remove(address As EIBGroupAddress) Implements IEIBManager(Of EIBGroupAddress, EIBDataContainer).Remove
            If _addresses.ContainsKey(address.ToUint16) Then _addresses.Remove(address.ToUint16)
        End Sub
    End Class
End Namespace